/* GUI CONVERTED from ecrels.p (converter v1.76) Tue Dec 31 10:45:21 2002 */
/* ecrels.p   - PCO  RELEASE                                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.10.1.7 $                                                     */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.4      LAST EDIT: 08/15/93   MODIFIED BY: QZL *H013*     */
/* REVISION: 7.4      LAST EDIT: 10/27/94   MODIFIED BY: ame *H578*     */
/* REVISION: 7.4      LAST EDIT: 02/08/95   MODIFIED BY: cpp *H0B7*     */
/* REVISION: 7.4      LAST EDIT: 04/10/95   MODIFIED BY: jpm *H0CH*     */
/*                               04/25/95            by: srk *H0D8*     */
/* REVISION: 7.4      LAST EDIT: 05/02/96   MODIFIED BY: rvw *H0KQ*     */
/* REVISION: 8.6      LAST EDIT: 08/19/96   MODIFIED BY: Joe Gawel     *K00C* */
/* REVISION: 8.6      LAST EDIT: 11/22/96   MODIFIED BY: Ashley Kurien *K046* */
/* REVISION: 8.6      LAST EDIT: 04/04/97   BY: *H0VN* Russ Witt              */
/* REVISION: 8.6      LAST EDIT: 05/22/97   MODIFIED BY: Joe Gawel     *K0BQ* */
/* REVISION: 8.6      LAST EDIT: 10/07/97   MODIFIED BY: John Worden   *K0LP* */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 12/23/98   BY: *L0CZ* Mugdha Tambe       */
/* REVISION: 9.0      LAST MODIFIED: 08/20/99   BY: *J3DF* Mugdha Tambe       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 07/11/00   BY: *N0FJ* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder      */
/* $Revision: 1.10.1.7 $    BY: Katie Hilbert         DATE: 12/27/02  ECO: *P0L8*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
{mfdtitle.i "2+ "}

define new shared variable ecmnbr1   like ecm_nbr format "x(24)".
define new shared variable rls       like mfc_logical.
define new shared variable cmtindx   as integer.
define new shared variable ps_ok     like mfc_logical no-undo.
define new shared variable progtitl  like dtitle.

define variable ecmnbr    like ecm_nbr.
define variable ecmid     like wo_lot.
define variable dbase     like si_db.
define variable ecmnbr2   like ecm_nbr.
define variable ecmid2    like wo_lot.
define variable dbase2    like si_db.
define variable ecmtype   like ecm_type.
define variable ecminit   like ecm_init.
define variable un_only   like mfc_logical.
define variable submit    like mfc_logical.
define variable submitted like mfc_logical no-undo.
define variable unsubmit  like mfc_logical.
define variable cmmt      like mfc_logical initial no.
define variable e_name    as character.
define variable leave-c   like mfc_logical no-undo.

define workfile rls_que
   field    ecm__nbr     like ecm_nbr      format "x(8)"
   field    ecm__id      like wo_lot       format "x(8)"
   field    ecm__dbase   like si_db        format "x(8)"
   field    ecm__cmtindx like ecm_cmtindx
   field    ecm__title   like ecm_title    format "x(26)"
   field    ecm__type    like ecm_type
   field    ecm__subdate like ecm_sub_date
   field    ecm__reldate like ecm_rel_date
   field    ecm__batched like ecm_batched.

{ecwndvar.i}  /*scrolling window variables*/

/* ecrels01.p is used as batchrun output for this program only */
if false then {gprun.i ""ecrelsrp.p""}
/*GUI*/ if global-beam-me-up then undo, leave.



/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   ecmnbr2            column-label "Number"
   ecmid2             column-label "ID"
   dbase2
   ecm__title         format "x(26)"
   rls                column-label "Rels"
   cmmt               label "Cmmt"
with frame a width 80 attr-space THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
ecmnbr               colon 13 label "Number"
   ecmid                colon 35
   dbase                colon 62
   ecm_doc_type         no-label format "x(3)"
   ecmtype              colon 13
   ecminit              colon 35 label "Created By"
   un_only              colon 62 label "Unreleased Only"
 SKIP(.4)  /*GUI*/
with frame aa  width 80 side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-aa-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame aa = F-aa-title.
 RECT-FRAME-LABEL:HIDDEN in frame aa = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame aa =
  FRAME aa:HEIGHT-PIXELS - RECT-FRAME:Y in frame aa - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME aa = FRAME aa:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame aa:handle).

FORM /*GUI*/  with frame w1 width 80 THREE-D /*GUI*/.

/*V8:HiddenDownFrame=w1 */

progtitl = dtitle.

find first pcc_ctrl no-lock no-error.
if (available pcc_ctrl and pcc_ecooff_date = ?)
   or not available pcc_ctrl then do:
   /*ECO Maintenance not disabled*/
   {pxmsg.i &MSGNUM=5652 &ERRORLEVEL=4}
   pause.
   hide message no-pause.
   return.
end.

assign
   window_row = 6
   window_down = 5
   un_only = yes.

loop-a:
repeat with frame aa on endkey undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.


   /*GUI: view frame dtitle. */
IF global-tool-bar AND global-tool-bar-handle ne ? THEN
  view global-tool-bar-handle. /*GUI*/

   view frame aa.
   view frame w1.
   view frame a.
   clear frame b all no-pause.
   clear frame a no-pause.
   clear frame w1 all no-pause.

   global_recid = ?.
   update
      ecmnbr
      ecmid
      dbase
      ecmtype
      ecminit
      un_only
   with frame aa
   editing:
      if frame-field = "ecmnbr" then do:
         /* FIND PRE/NEXT */

         {mfnp05.i ecm_mstr ecm_mstr
            "(ecm_rel_date = ? and ecm_appr_date <> ?
              and ecm_close_date = ?)"
            ecm_nbr "input ecmnbr"}

         if global_recid <> ? then do:
            recno = global_recid.
            find ecm_mstr where recid(ecm_mstr) = recno
            no-lock no-error.
            global_recid = ?.
         end.

         if recno <> ? then
            display
               substring(ecm_nbr,1,8)  @ ecmnbr
               substring(ecm_nbr,9,8)  @ ecmid
               substring(ecm_nbr,17,8) @ dbase
               ecm_doc_type
               ecm_type                @ ecmtype
               ecm_init                @ ecminit
            with frame aa.
      end.
      else if frame-field = "ecmtype" then do:
         recno = ?.

         {mfnp.i pct_mstr ecmtype  pct_type ecmtype pct_type pct_type}
         if recno <> ? then display pct_type @ ecmtype with frame aa.
      end.
      else if frame-field = "ecminit" then do:
         recno = ?.
         {mfnp.i usr_mstr ecminit usr_userid ecminit usr_userid
            usr_userid }
         if recno <> ? then display usr_userid @ ecminit with frame aa.
      end.
      else do:
         readkey.
         apply lastkey.
      end.
   end.
   global_recid = ?.

   for each rls_que exclusive-lock:
      delete rls_que.
   end.

   assign
      ecmnbr = string(ecmnbr, "x(8)")
      ecmid  = string(ecmid, "x(8)")
      dbase  = string(dbase, "x(8)").

   for each ecm_mstr where
      (substring(ecm_nbr,1,8) >= ecmnbr or ecmnbr = "") and
      (substring(ecm_nbr,9,8)  = ecmid  or ecmid  = "") and
      (substring(ecm_nbr,17,8) = dbase  or dbase  = "") and
      ( right-trim( string( substring(ecm_nbr,25,1),"x(1)" ) ) = "" ) and
      ( right-trim( ecm_type ) = ecmtype or ecmtype = "" ) and
      ( right-trim( ecm_init ) = ecminit or ecminit = "" ) and
      (ecm_doc_type = "PCO") and (ecm_close_date = ?) and
      (ecm_appr_date <> ?) and
      ((ecm_rel_date = ? and not ecm_batched and un_only) or
      (ecm_rel_date = ? and not un_only)) no-lock by ecm_nbr:

      create rls_que.
      assign
         ecm__nbr     = substring(ecm_nbr,1,8)
         ecm__id      = substring(ecm_nbr,9,8)
         ecm__dbase   = substring(ecm_nbr,17,8)
         ecm__cmtindx = ecm_cmtindx
         ecm__title   = ecm_title
         ecm__type    = ecm_type
         ecm__subdate = ecm_sub_date
         ecm__reldate = ecm_rel_date
         ecm__batched = ecm_batched.
   end.

   loop-b:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

      clear frame a no-pause.
      clear frame w1 all no-pause.
      if keyfunction(lastkey) = "end-error"
         and leave-c = no then undo loop-a, retry.
      {ecwindow.i rls_que
         "ecm__nbr ecm__id ecm__dbase
           ecm__title ecm__subdate ecm__batched"
         ecm__nbr
         "/**/"
         "yes"
         """"
         "width 80 attr-space"
         "1"
         "ecm__nbr ecm__id ecm__dbase"}
      leave-c = no.
      global_recid = recidarray[i].

      if lastkey = keycode("GO") or lastkey = keycode("F1")
         or lastkey = 301 or keyfunction(lastkey) = "GO"
         or lastkey = keycode("RETURN")
      then
      block-c:
      do transaction with frame a on endkey undo loop-b, retry loop-b:
/*GUI*/ if global-beam-me-up then undo, leave.

         leave-c = yes.
         global_recid = recidarray[i].

         find rls_que where recid(rls_que) = global_recid
         no-lock no-error.
         if available rls_que then do:
            rls = yes.

            if not ecm__batched then display rls.
            else display "" @ rls.
            if ecm__cmtindx = 0 then cmmt = no.
            else cmmt = yes.
            display
               ecm__nbr   @ ecmnbr2
               ecm__id    @ ecmid2
               ecm__dbase @ dbase2
               ecm__title
               cmmt
            with frame a.

            set ecmnbr2 ecmid2 dbase2 with frame a
            editing:
               if frame-field = "ecmnbr2" then do:
                  global_recid = ?.

                  /* CHANGED FIRST PARAMETER ECM_NBR . STRING FUNCTION IS REPLACED BY */
                  /* TRIM AND REMOVED FORMAT FOR ECM_NBR                              */
                  {mfnp05.i ecm_mstr ecm_mstr
                     "(trim(substring(ecm_nbr,25,1)) = """" and
                       (ecm_type = ecmtype or ecmtype = """") and
                       (ecm_init = ecminit or ecminit = """") and
                       (ecm_doc_type = ""PCO"") and
                       ecm_appr_date <> ? and ecm_rel_date = ? and
                       ((not ecm_batched and un_only) or not un_only) and
                       ecm_close_date = ?)" ecm_nbr "input ecmnbr2"}

                  if global_recid <> ? then do:
                     recno = global_recid.
                     find ecm_mstr where recid(ecm_mstr) = recno
                     no-lock no-error.
                  end.

                  if recno <> ? then do:
                     if not ecm_batched then display rls.
                     else display "" @ rls.

                     if ecm_cmtindx = 0 then cmmt = no.
                     else cmmt = yes.
                     display
                        substring(ecm_nbr,1,8)  @ ecmnbr2
                        substring(ecm_nbr,9,8)  @ ecmid2
                        substring(ecm_nbr,17,8) @ dbase2
                        cmmt.
                  end.
               end.
               else do:
                  readkey.
                  apply lastkey.
               end.
            end.

            assign
               ecmnbr2 = string(ecmnbr2, "x(8)")
               ecmid2  = string(ecmid2, "x(8)")
               dbase2  = string(dbase2, "x(8)").

            find first rls_que
               where ecm__nbr = ecmnbr2 and
                     ecm__id  = ecmid2  and
                     ecm__dbase = dbase2 no-error.
            if not available rls_que then do:
               /* NO RECORD AVAILABLE BASED ON SELECTION CRITERIA */
               {pxmsg.i &MSGNUM=5657 &ERRORLEVEL=3}
               hide message.
               undo block-c, leave block-c.
            end.
            global_recid = recid(rls_que).

            block-updt:
            repeat on endkey undo block-c, leave block-c:
/*GUI*/ if global-beam-me-up then undo, leave.


               ecmnbr1 = string(ecmnbr2, "x(8)")
                       + string(ecmid2,"x(8)")
                       + string(dbase2,"x(8)").
               find ecm_mstr exclusive-lock where ecm_nbr = ecmnbr1
                  no-error no-wait.
               if locked(ecm_mstr) then do:
                  /*RECORD LOCKED BY ANOTHER USER */
                  {pxmsg.i &MSGNUM=7422 &ERRORLEVEL=4}
                  hide message.
                  undo block-c, leave block-c.
               end.
               if not available ecm_mstr then do:
                  /* DATA CHANGED AND RERUN THIS PROGRAM REQUIRED */
                  {pxmsg.i &MSGNUM=5629 &ERRORLEVEL=3}
                  undo loop-b, leave loop-b.
               end.

               update rls cmmt with frame a.

               if cmmt then do on endkey undo, leave:
                  hide frame w1 no-pause.
                  hide frame a no-pause.
                  global_ref = getTermLabel("COMMENTS",8)    + " - " +
                               getTermLabel("SUBMISSION",10) + ", "  +
                               getTermLabel("APPROVAL",8)    + ", "  +
                               getTermLabel("RELEASE",7).
                  cmtindx = ecm_cmtindx.
                  {gprun.i ""gpcmmt01.p"" "(input ""ecm_mstr"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  ecm_cmtindx = cmtindx.
                  global_ref = "".
                  view frame aa.
                  view frame w1.
                  view frame a.
               end.

               if rls = yes then
               block-bat:
               do on endkey undo block-c, leave block-c
                     on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                  if not ecm_batched and ecm_rel_date <> ? then do:
                     /* PCO/PCR already released or distributed */
                     {pxmsg.i &MSGNUM=2162 &ERRORLEVEL=3}
                     undo block-updt, retry block-updt.
                  end.

                  {gprun.i ""eccyck.p"" "(input ecm_nbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  if not ps_ok then do:
                     /* CYCLIC PRODUCT STRUCTURE NOT ALLOWED. */
                     {pxmsg.i &MSGNUM=206 &ERRORLEVEL=3}
                     hide message.
                     undo block-c, leave block-c.
                  end.

                  do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                     bcdparm = "".
                     e_name = execname.
                     execname = "ecrels01.p".
                     {mfquoter.i ecmnbr1}
                     {mfquoter.i progtitl}
                     {ecselbat.i}
                     hide message.
                     if batch_id = "" then do:

                        {gprun.i ""ecrels02.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

                        do on endkey undo, leave:
                           /*PCO has been distributed*/
                           {pxmsg.i &MSGNUM=2178 &ERRORLEVEL=1}
                           pause.
                        end.

                        ecm_batched = no.
                        find first rls_que where
                           ecm__nbr   = substring(ecm_nbr,1,8) and
                           ecm__id    = substring(ecm_nbr,9,8) and
                           ecm__dbase = substring(ecm_nbr,17,8) no-error.
                        if available rls_que then do:
                           delete rls_que.
                           hide message.
                           find first rls_que no-error.
                           if not available rls_que then
                              next loop-a.
                        end.
                     end.
                     else
                        assign
                           execname    = e_name
                           ecm__batched = true
                           ecm_batched = yes
                           batch_id = "".
                  end.
/*GUI*/ if global-beam-me-up then undo, leave.

               end.
               else do:
                  assign
                     ecm__batched = false
                     ecm_batched = no.
                  /* Batch request needs to be deleted */
                  /* in batch maintenance function     */
                  {pxmsg.i &MSGNUM=5665 &ERRORLEVEL=2}
                  hide message.
               end.
               release ecm_mstr.
               leave.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* end of block-c */
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* end of loop-b */
end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* end of loop-a */
global_recid = ?.
